<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Stopping and Restarting Nagios</title>

<STYLE type="text/css">
<!--
        .Default { font-family: verdana,arial,serif; font-size: 8pt; }
        .PageTitle { font-family: verdana,arial,serif; font-size: 12pt; font-weight: bold; }
-->      
</STYLE>

</head>

<body bgcolor="#FFFFFF" text="black" class="Default">

<p>
<div align="center">
<h2 class="PageTitle">Stopping And Restarting Nagios</h2>
</div>
</p>
<hr>

<p>
Once you have Nagios up and running, you may need to stop the process or reload the configuration
data "on the fly".  This section describes how to do just that.
</p>

<p>
<font color="red"><strong>IMPORTANT:</strong></font>  Before you restart Nagios, make sure that you have <a href="verifyconfig.html">verified the configuration data</a> using the -v command line switch, <i>especially</i> if you have made any changes to your <a href="config.html">config files</a>.  If Nagios encounters problem with one of the config files when it restarts, it will log an error and terminate.
</p>

<p>
<strong><u>Stopping And Restarting With The Init Script</u></strong>
</p>

<p>
If you have installed the sample init script to your /etc/rc.d/init.d directory you can stop and restart Nagios easily.  If you haven't, skip this section and read how to do it manually below.  I'll assume that you named the init script <b>Nagios</b> in the examples below...
</p>

<p>
<table border="1" class="Default">
<tr>
<td bgcolor="#cbcbcb"><strong>Desired Action</strong></td>
<td bgcolor="#cbcbcb" nowrap><strong>Command</strong></td>
<td bgcolor="#cbcbcb"><strong>Description</strong></td>
</tr>
<tr>
<td>Stop Nagios</td>
<td nowrap><font color="red"><strong>/etc/rc.d/init.d/nagios stop</strong></font></td>
<td>This kills the Nagios process</td>
</tr>
<tr>
<td>Restart Nagios</td>
<td nowrap><font color="red"><strong>/etc/rc.d/init.d/nagios restart</strong></font></td>
<td>This kills the current Nagios process and then starts Nagios up again</td>
</tr>
<tr>
<td>Reload Configuration Data</td>
<td nowrap><font color="red"><strong>/etc/rc.d/init.d/nagios reload</strong></font></td>
<td>Sends a SIGHUP to the Nagios process, causing it to flush its current configuration data, reread the configuration files, and start monitoring again</td>
</tr>
</table>
</p>

<p>
Stopping, restarting, and reloading Nagios are fairly simple with an init script and I would highly recommend you use one if at all possible.
</p>

<p>
<strong><u>Stopping and Restarting Nagios Manually</u></strong>
</p>

<p>
If you aren't using an init script to start Nagios, you'll have to do things manually.  First you'll have to find the process ID that Nagios is running under and then you'll have to use the <i>kill</i> command to terminate the application or make it reload the configuration data by sending it the proper signal.  Directions for doing this are outlined below...
</p>

<p>
<strong><u>Finding The Nagios Process ID</u></strong>
</p>

<p>
First off, you will need to know the process id that Nagios is running as.  To do that, just type the 
following command at a shell prompt:
</p>
<p>
<strong><font color="red">ps axu | grep nagios</font></strong>
</p>
<p>
The output should look something like this:
<pre>
nagios  6808  0.0  0.7   840   352  p3 S    13:44   0:00 grep nagios
nagios 11149  0.2  1.0   868   488  ?  S   Feb 27   6:33 /usr/local/nagios/bin/nagios nagios.cfg
</pre>
From the program output, you will notice that Nagios was started by user <b>nagios</b> and is running as process id <b>11149</b>.
</p>

<p>
<strong><u>Manually Stopping Nagios</u></strong>
</p>

<p>
In order to stop Nagios, use the <i>kill</i> command as follows...
</p>
<p>
<strong><font color="red">kill 11149</font></strong>
</p>
<p>
You should replace <b>11149</b> with the actual process id that Nagios is running as on your machine.
</p>

<p>
<strong><u>Manually Restarting Nagios</u></strong>
</p>

<p>
If you have modified the configuration data, you will want to restart Nagios and have it re-read the new configuration.  If you have changed the source code and recompiled the main Nagios executable you should <i>not</i> use this method.  Instead, stop Nagios by killing it (as outlined above) and restart it manually.  Restarting Nagios using the method below does not actually reload Nagios - it just causes Nagios to flush its current configuration, re-read the new configuration, and start monitoring all over again.  To restart Nagios, you need to send the <b>SIGHUP</b> signal to Nagios.  Assuming that the process id for Nagios is <b>11149</b> (taken from the example above), use the following command:
</p>
<p>
<strong><font color="red">kill -HUP 11149</font></strong>
</p>
<p>
Remember, you will need to replace <b>11149</b> with the actual process id that Nagios is running as on your machine.
</p>


<hr>

</body>
</html>
